function [xF] = ReplicateCF(C,F,cT) 

 
  
  [N,T] = size(C); 
  [maxcT,maxind] = max(cT,[],2); 
  
  
  w = zeros(N,T); 
  Cout = zeros(N,T); 
  for j = 1:N
    
    for i = 1:maxind(j,1); 
         
      if i == 1
        Cout(j,i) = C(j,i);  
        w(j,i) = -Cout(j,i); 
        lT = cT(j,i); 
      elseif (C(j,i) <= 0 && i < maxind(j,1))
        Cout(j,i) = C(j,i);   
        w(j,i) = w(j,i-1)*(F(j,i)/F(j,i-1)) - Cout(j,i);
      elseif i < maxind(j,1) 
        trat = (cT(j,i)-lT)/(10-lT); 
        Cout(j,i) = min(max(trat,0),1)*w(j,i-1) + (F(j,i)/F(j,i-1)-1)*w(j,i-1); 
        w(j,i) = w(j,i-1)*(F(j,i)/F(j,i-1)) - Cout(j,i);
        lT = cT(j,i); 
      else 
        Cout(j,i) = (F(j,i)/F(j,i-1))*w(j,i-1); 
      end
      
    end
  end
  
  xF = Cout; 
  
  %%global ws
  %%ws = w;
